package com.youhong.teethcare.customviews;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.youhong.teethcare.R;

/**
 * Created by Administrator on 2018/3/31 0031.
 */

public class TeethModelRelativeLayout extends RelativeLayout {
    public TeethModelRelativeLayout(Context context) {
        super(context);
        getViews(context);
        adjustLayoutParams();

    }


    public TeethModelRelativeLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        getViews(context);
        adjustLayoutParams();

    }

    public TeethModelRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        getViews(context);
        adjustLayoutParams();
    }

    ImageView iv_upper, iv_upperLeft, iv_upperRight, iv_under, iv_underLeft, iv_underRight;

    private void getViews(Context context) {
        LayoutInflater.from(context).inflate(R.layout.rl_teethmodel, this);


//        iv_upper = findViewById(R.id.teethModel_iv_upper);
//        iv_upperLeft = findViewById(R.id.teethModel_iv_upperLeft);
//        iv_upperRight = findViewById(R.id.teethModel_iv_upperRight);
//        iv_under = findViewById(R.id.teethModel_iv_under);
//        iv_underLeft = findViewById(R.id.teethModel_iv_underLeft);
//        iv_underRight = findViewById(R.id.teethModel_iv_underRight);
    }

    private void adjustLayoutParams() {

        /** Upper**/
        RelativeLayout.LayoutParams upper_layoutParams = (RelativeLayout.LayoutParams) iv_upper.getLayoutParams();
        upper_layoutParams.width = (int) (width * 0.45f);
        upper_layoutParams.height = (int) (height * 0.09f);
        upper_layoutParams.leftMargin = (int) (width * 0.27f);


        iv_upper.setLayoutParams(upper_layoutParams);

        /** Under**/
        RelativeLayout.LayoutParams under_layoutParams = (RelativeLayout.LayoutParams) iv_under.getLayoutParams();
        under_layoutParams.width = (int) (width * 0.39f);
        under_layoutParams.height = (int) (height * 0.09f);
        under_layoutParams.topMargin = (int) -(height * 0.02f);
        under_layoutParams.leftMargin = (int) (width * 0.30f);
        iv_under.setLayoutParams(under_layoutParams);

        /**UpperLeft*/
        RelativeLayout.LayoutParams upperLeft_layoutParams = (RelativeLayout.LayoutParams) iv_upperLeft.getLayoutParams();
        upperLeft_layoutParams.leftMargin = (int) (width * 0.15f);
        upperLeft_layoutParams.topMargin = (int) (height * 0.065f);
        upperLeft_layoutParams.width = (int) (width * 0.19f);
        upperLeft_layoutParams.height = (int) (height * 0.23f);

        iv_upperLeft.setLayoutParams(upperLeft_layoutParams);

        /**UpperRight*/
        RelativeLayout.LayoutParams upperRight_layoutParams = (RelativeLayout.LayoutParams) iv_upperRight.getLayoutParams();
        upperRight_layoutParams.leftMargin = (int) (width * 0.65f);
        upperRight_layoutParams.topMargin = (int) (height * 0.065f);
        upperRight_layoutParams.width = (int) (width * 0.19f);
        upperRight_layoutParams.height = (int) (height * 0.23f);
        iv_upperRight.setLayoutParams(upperRight_layoutParams);

        /**UnderLeft*/
        RelativeLayout.LayoutParams underLeft_layoutParams = (RelativeLayout.LayoutParams) iv_underLeft.getLayoutParams();
        underLeft_layoutParams.leftMargin = (int) (width * 0.13f);
        underLeft_layoutParams.topMargin = (int) (height * 0.06f);
        underLeft_layoutParams.width = (int) (width * 0.25f);
        underLeft_layoutParams.height = (int) (height * 0.23f);

        iv_underLeft.setLayoutParams(underLeft_layoutParams);

        /**UnderRight*/

        RelativeLayout.LayoutParams underRight_layoutParams = (RelativeLayout.LayoutParams) iv_underRight.getLayoutParams();
        underRight_layoutParams.leftMargin = (int) (width * 0.62f);
        underRight_layoutParams.topMargin = (int) (height * 0.06f);
        underRight_layoutParams.width = (int) (width * 0.25f);
        underRight_layoutParams.height = (int) (height * 0.23f);

        iv_underRight.setLayoutParams(underRight_layoutParams);


    }

    int height, width;

    public void resize(int width, int height) {

        this.height = height;
        this.width = width;
        adjustLayoutParams();

    }

    //Positions
    public static final int POSITION_UPPER = 0;
    public static final int POSITION_UPPER_LEFT = 1;
    public static final int POSITION_UPPER_RIGHT = 2;
    public static final int POSITION_UNDER = 3;
    public static final int POSITION_UNDER_LEFT = 4;
    public static final int POSITION_UNDER_RIGHT = 5;

//    public void areaDisplay(byte area1, byte area2, byte area3,
//                            byte area4, byte area5, byte area6) {
//
//        //下门牙
//        switch (area1) {
//            case 0:
//                iv_under.setImageDrawable(getResources().getDrawable(R.mipmap.under_yellow));
//                break;
//            case 1:
//                iv_under.setImageDrawable(getResources().getDrawable(R.mipmap.under_inner_yellow));
//                break;
//            case 4:
//                iv_under.setImageDrawable(getResources().getDrawable(R.mipmap.under_outer_yellow));
//                break;
//            case 5:
//                iv_under.setImageDrawable(getResources().getDrawable(R.mipmap.under_white));
//                break;
//        }
//        //上门牙
//        switch (area2) {
//            case 0:
//                iv_upper.setImageDrawable(getResources().getDrawable(R.mipmap.upper_yellow));
//                break;
//            case 1:
//                iv_upper.setImageDrawable(getResources().getDrawable(R.mipmap.upper_inner_yellow));
//                break;
//            case 4:
//                iv_upper.setImageDrawable(getResources().getDrawable(R.mipmap.upper_outer_yellow));
//                break;
//            case 5:
//                iv_upper.setImageDrawable(getResources().getDrawable(R.mipmap.upper_white));
//                break;
//        }
//
//        //左下板牙
//        switch (area3) {
//            case 0:
//                iv_underLeft.setImageDrawable(getResources().getDrawable(R.mipmap.underleft_yellow));
//                break;
//            case 1:
//                iv_underLeft.setImageDrawable(getResources().getDrawable(R.mipmap.underleft_outer_white));
//                break;
//            case 2:
//                iv_underLeft.setImageDrawable(getResources().getDrawable(R.mipmap.underleft_middle_white));
//                break;
//            case 3:
//                iv_underLeft.setImageDrawable(getResources().getDrawable(R.mipmap.underleft_inner_yellow));
//                break;
//            case 4:
//                iv_underLeft.setImageDrawable(getResources().getDrawable(R.mipmap.underleft_inner_white));
//                break;
//            case 5:
//                iv_underLeft.setImageDrawable(getResources().getDrawable(R.mipmap.underleft_middle_yellow));
//                break;
//            case 6:
//                iv_underLeft.setImageDrawable(getResources().getDrawable(R.mipmap.underleft_outer_yellow));
//                break;
//            case 7:
//                iv_underLeft.setImageDrawable(getResources().getDrawable(R.mipmap.underleft_white));
//                break;
//        }
//
//        //左上板牙
//        switch (area4) {
//            case 0:
//                iv_upperLeft.setImageDrawable(getResources().getDrawable(R.mipmap.upperleft_yellow));
//                break;
//            case 1:
//                iv_upperLeft.setImageDrawable(getResources().getDrawable(R.mipmap.upperleft_outer_white));
//                break;
//            case 2:
//                iv_upperLeft.setImageDrawable(getResources().getDrawable(R.mipmap.upperleft_middle_white));
//                break;
//            case 3:
//                iv_upperLeft.setImageDrawable(getResources().getDrawable(R.mipmap.upperleft_inner_yellow));
//                break;
//            case 4:
//                iv_upperLeft.setImageDrawable(getResources().getDrawable(R.mipmap.upperleft_inner_white));
//                break;
//            case 5:
//                iv_upperLeft.setImageDrawable(getResources().getDrawable(R.mipmap.upperleft_middle_yellow));
//                break;
//            case 6:
//                iv_upperLeft.setImageDrawable(getResources().getDrawable(R.mipmap.upperleft_outer_yellow));
//                break;
//            case 7:
//                iv_upperLeft.setImageDrawable(getResources().getDrawable(R.mipmap.upperleft_white));
//                break;
//        }
//
//
//        //右下板牙
//        switch (area5) {
//            case 0:
//                iv_underRight.setImageDrawable(getResources().getDrawable(R.mipmap.underright_yellow));
//                break;
//            case 1:
//                iv_underRight.setImageDrawable(getResources().getDrawable(R.mipmap.underright_outer_white));
//                break;
//            case 2:
//                iv_underRight.setImageDrawable(getResources().getDrawable(R.mipmap.underright_middle_white));
//                break;
//            case 3:
//                iv_underRight.setImageDrawable(getResources().getDrawable(R.mipmap.underright_inner_yellow));
//                break;
//            case 4:
//                iv_underRight.setImageDrawable(getResources().getDrawable(R.mipmap.underright_inner_white));
//                break;
//            case 5:
//                iv_underRight.setImageDrawable(getResources().getDrawable(R.mipmap.underright_middle_yellow));
//                break;
//            case 6:
//                iv_underRight.setImageDrawable(getResources().getDrawable(R.mipmap.underright_outer_yellow));
//                break;
//            case 7:
//                iv_underRight.setImageDrawable(getResources().getDrawable(R.mipmap.underright_white));
//                break;
//        }
//
//        //右上板牙
//        switch (area6) {
//            case 0:
//                iv_upperRight.setImageDrawable(getResources().getDrawable(R.mipmap.upperright_yellow));
//                break;
//            case 1:
//                iv_upperRight.setImageDrawable(getResources().getDrawable(R.mipmap.upperright_outer_white));
//                break;
//            case 2:
//                iv_upperRight.setImageDrawable(getResources().getDrawable(R.mipmap.upperright_middle_white));
//                break;
//            case 3:
//                iv_upperRight.setImageDrawable(getResources().getDrawable(R.mipmap.upperright_inner_yellow));
//                break;
//            case 4:
//                iv_upperRight.setImageDrawable(getResources().getDrawable(R.mipmap.upperright_inner_white));
//                break;
//            case 5:
//                iv_upperRight.setImageDrawable(getResources().getDrawable(R.mipmap.upperright_middle_yellow));
//                break;
//            case 6:
//                iv_upperRight.setImageDrawable(getResources().getDrawable(R.mipmap.upperright_outer_yellow));
//                break;
//            case 7:
//                iv_upperRight.setImageDrawable(getResources().getDrawable(R.mipmap.upperright_white));
//                break;
//
//        }
//    }

}
